package com.qf.openapi.wxpay.utils;

import com.github.wxpay.sdk.WXPay;
import com.github.wxpay.sdk.WXPayConfig;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class SDKTest {
    public static void main(String[] args) throws Exception {

//        unifiedOrder();
        // 商户自己的订单编号
        String orderID = "202307131029888";

        String appid = "wx632c8f211f8122c6";
        String mch_id = "1497984412";
        String appkey = "sbNCm1JnevqI36LrEaxFwcaT0hkGxFnC";

        // 查该订单支付支付成功了
        WXPay wxPay = new WXPay(new WXPayConfig() {
            @Override
            public String getAppID() {
                return appid;
            }

            @Override
            public String getMchID() {
                return mch_id;
            }

            @Override
            public String getKey() {
                return appkey;
            }

            @Override
            public InputStream getCertStream() {
                return null;
            }

            @Override
            public int getHttpConnectTimeoutMs() {
                return 0;
            }

            @Override
            public int getHttpReadTimeoutMs() {
                return 0;
            }
        });

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("out_trade_no",orderID);

        Map<String, String> resultmap = wxPay.orderQuery(hashMap);
        System.out.println(resultmap);

    }

    private static void unifiedOrder() throws Exception {
        String appid = "wx632c8f211f8122c6";
        String mch_id = "1497984412";
        String appkey = "sbNCm1JnevqI36LrEaxFwcaT0hkGxFnC";

        // 构建核心对象
        WXPay wxPay = new WXPay(new WXPayConfig() {
            @Override
            public String getAppID() {
                return appid;
            }

            @Override
            public String getMchID() {
                return mch_id;
            }

            @Override
            public String getKey() {
                return appkey;
            }

            @Override
            public InputStream getCertStream() {
                return null;
            }

            @Override
            public int getHttpConnectTimeoutMs() {
                return 0;
            }

            @Override
            public int getHttpReadTimeoutMs() {
                return 0;
            }
        });
        // 组织参数
        HashMap<String,String> data = new HashMap<>();
        data.put("body","tesetproduct");  //商品描述
        data.put("out_trade_no","202307131029888");               //使用当前用户订单的编号作为当前支付交易的交易号
        data.put("fee_type","CNY");                     //支付币种
        data.put("total_fee","1");
        data.put("trade_type","NATIVE");                //交易类型
        data.put("notify_url","http://47.118.45.73:8080/pay/callback");           //设置支付完成时的回调方法接口
        // 调用统计下单接口，用于获取支付rul
        Map<String, String> resultmap = wxPay.unifiedOrder(data);
        System.out.println(resultmap);
    }
}
